PLOT
Functions
#______________________
# PLOT IN 2D
plot.covariates <- function(plotDF=umap.df){
p1 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = host_disease))+
geom_point(size=1, alpha=0.6) +
scale_color_manual(values=c("blue", "red", "black"), name="Disease phenotype")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
p2 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = host_subtype))+
geom_point(size=1, alpha=0.6) +
scale_color_manual(values=c("#EFF3FF", "#D95F02", "#7570B3", "#E7298A", "#FEEDDE", "grey"), name="Disease subtype")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
p3 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = sequencing_tech))+
geom_point(size=1, alpha=0.6) +
scale_color_manual(values=c('#6600FF', '#33CC33', '#006600', '#FF6633'), name="seq_tech")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
p4 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = author))+
geom_point(size=1, alpha=0.6) +
scale_color_manual(values=brewer.paired(n=13), name="Dataset")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
show(ggpubr::ggarrange(p1, p2, p3, p4, nrow=2, ncol=2))
}
#______________________
# PLOT IN 3D
plot3D <- function(plotDF=umap.df, coloring="host_disease", colorPal=c("blue", "red", "black"), taxLevel="Genus"){
# 3D
plotly::plot_ly() %>%
add_trace(data=umap.df,
x=~UMAP_1, y=~UMAP_2, z=~UMAP_3,
color=~plotDF[,coloring],
colors=colorPal,
type="scatter3d",
mode="markers",
marker=list(size=5)) %>%
layout(title=coloring)
}
#______________________
# PLOT PHYLA LOG RATIOS
plot.logRatio <- function(plotDF=umap.df){
p1 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = LogRatio_FirmBact))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(plotDF$LogRatio_FirmBact), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=8),
axis.title = element_text(size=5),
axis.text = element_text(size=5))+
labs(color="Firmicutes/Bacteroidota")
p2 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = LogRatio_FirmAct))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(plotDF$LogRatio_FirmAct), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=8),
axis.title = element_text(size=5),
axis.text = element_text(size=5))+
labs(color="Firmicutes/Actinobacteria")
p3 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = LogRatio_BactAct))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(plotDF$LogRatio_BactAct), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=8),
axis.title = element_text(size=5),
axis.text = element_text(size=5))+
labs(color="Bacteroidota/Actinobacteria")
show(ggpubr::ggarrange(p1, p2, p3, nrow=2, ncol=2))
}
#______________________
# PLOT PHYLA REL ABUNDANCE
plot.relAbundance <- function(plotDF=umap.df){
p1 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = Firmicutes))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(plotDF$Firmicutes), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
p2 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = Bacteroidota))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(plotDF$Bacteroidota), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
p3 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = Actinobacteriota))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(plotDF$Actinobacteriota), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
p4 <- ggplot(plotDF, aes(x = UMAP_1, y = UMAP_2, color = Proteobacteria))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(plotDF$Proteobacteria), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank(),
legend.key.size = unit(0.25, 'cm'),
legend.text = element_text(size=6),
legend.title = element_text(size=10),
axis.title = element_text(size=5),
axis.text = element_text(size=5))
show(ggpubr::ggarrange(p1, p2, p3, p4, nrow=2, ncol=2))
}
Phylum level
# GET UMAP DF
umap.df <- getUMAP(taxLevel="Phylum")
## [1] 2220 11
## [1] 2220 21
# Plot by host_disease, host_subtype, sequencing_tech, author/dataset (in 2D)
plot.covariates()

# Plot3D
# plot3D(coloring="host_disease", colorPal=c("blue", "red", "black"), taxLevel="Phylum")
# plot3D(coloring="host_subtype", colorPal=c("#EFF3FF", "#D95F02", "#7570B3", "#E7298A", "#FEEDDE", "grey"), taxLevel="Phylum")
# plot3D(coloring="sequencing_tech", colorPal=c('#6600FF', '#33CC33', '#006600', '#FF6633'), taxLevel="Phylum")
# plot3D(coloring="author", colorPal=brewer.paired(n=13), taxLevel="Phylum")
# Plot by Shannon index (in 2D)
ggplot(umap.df, aes(x = UMAP_1, y = UMAP_2, color = shannon))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(umap.df$shannon), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank())

# plot3D(coloring="shannon", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
# Plot log ratios (in 2D)
plot.logRatio()

# Plot 3D
# plot3D(coloring="LogRatio_FirmBact", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
# plot3D(coloring="LogRatio_FirmAct", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
# plot3D(coloring="LogRatio_BactAct", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
# By Phyla relative abundances (in 2D)
plot.relAbundance()

# By Phyla relative abundances (in 3D)
# plot3D(coloring="Firmicutes", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
# plot3D(coloring="Bacteroidota", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
# plot3D(coloring="Actinobacteriota", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
# plot3D(coloring="Proteobacteria", colorPal=rev(brewer.rdbu(50)), taxLevel="Phylum")
Class level
# GET UMAP DF
umap.df <- NULL
umap.df <- getUMAP(taxLevel="Class")
## [1] 2220 11
## [1] 2220 21
# Plot by host_disease, host_subtype, sequencing_tech, author/dataset (in 2D)
plot.covariates()

# Plot3D
# plot3D(coloring="host_disease", colorPal=c("blue", "red", "black"), taxLevel="Class")
# plot3D(coloring="host_subtype", colorPal=c("#EFF3FF", "#D95F02", "#7570B3", "#E7298A", "#FEEDDE", "grey"), taxLevel="Class")
# plot3D(coloring="sequencing_tech", colorPal=c('#6600FF', '#33CC33', '#006600', '#FF6633'), taxLevel="Class")
# plot3D(coloring="author", colorPal=brewer.paired(n=13), taxLevel="Class")
# Plot by Shannon index (in 2D)
ggplot(umap.df, aes(x = UMAP_1, y = UMAP_2, color = shannon))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(umap.df$shannon), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank())

# plot3D(coloring="shannon", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
# Plot log ratios (in 2D)
plot.logRatio()

# Plot 3D
# plot3D(coloring="LogRatio_FirmBact", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
# plot3D(coloring="LogRatio_FirmAct", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
# plot3D(coloring="LogRatio_BactAct", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
# By Phyla relative abundances (in 2D)
plot.relAbundance()

# By Phyla relative abundances (in 3D)
# plot3D(coloring="Firmicutes", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
# plot3D(coloring="Bacteroidota", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
# plot3D(coloring="Actinobacteriota", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
# plot3D(coloring="Proteobacteria", colorPal=rev(brewer.rdbu(50)), taxLevel="Class")
Order level
# GET UMAP DF
umap.df <- NULL
umap.df <- getUMAP(taxLevel="Order")
## [1] 2220 11
## [1] 2220 21
# Plot by host_disease, host_subtype, sequencing_tech, author/dataset (in 2D)
plot.covariates()

# Plot3D
# plot3D(coloring="host_disease", colorPal=c("blue", "red", "black"), taxLevel="Order")
# plot3D(coloring="host_subtype", colorPal=c("#EFF3FF", "#D95F02", "#7570B3", "#E7298A", "#FEEDDE", "grey"), taxLevel="Order")
# plot3D(coloring="sequencing_tech", colorPal=c('#6600FF', '#33CC33', '#006600', '#FF6633'), taxLevel="Order")
# plot3D(coloring="author", colorPal=brewer.paired(n=13), taxLevel="Order")
# Plot by Shannon index (in 2D)
ggplot(umap.df, aes(x = UMAP_1, y = UMAP_2, color = shannon))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(umap.df$shannon), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank())

# plot3D(coloring="shannon", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
# Plot log ratios (in 2D)
plot.logRatio()

# Plot 3D
# plot3D(coloring="LogRatio_FirmBact", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
# plot3D(coloring="LogRatio_FirmAct", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
# plot3D(coloring="LogRatio_BactAct", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
# By Phyla relative abundances (in 2D)
plot.relAbundance()

# By Phyla relative abundances (in 3D)
# plot3D(coloring="Firmicutes", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
# plot3D(coloring="Bacteroidota", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
# plot3D(coloring="Actinobacteriota", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
# plot3D(coloring="Proteobacteria", colorPal=rev(brewer.rdbu(50)), taxLevel="Order")
Family level
# GET UMAP DF
umap.df <- NULL
umap.df <- getUMAP(taxLevel="Family")
## [1] 2220 11
## [1] 2220 21
# Plot by host_disease, host_subtype, sequencing_tech, author/dataset (in 2D)
plot.covariates()

# Plot3D
plot3D(coloring="host_disease", colorPal=c("blue", "red", "black"), taxLevel="Family")
plot3D(coloring="host_subtype", colorPal=c("#EFF3FF", "#D95F02", "#7570B3", "#E7298A", "#FEEDDE", "grey"), taxLevel="Family")
plot3D(coloring="sequencing_tech", colorPal=c('#6600FF', '#33CC33', '#006600', '#FF6633'), taxLevel="Family")
plot3D(coloring="author", colorPal=brewer.paired(n=13), taxLevel="Family")
# Plot by Shannon index (in 2D)
ggplot(umap.df, aes(x = UMAP_1, y = UMAP_2, color = shannon))+
geom_point(size=1) +
scale_color_gradient2(midpoint=mean(umap.df$shannon), low="blue", mid="white", high="red")+
theme(panel.grid = element_blank(),
panel.background=element_blank())
